'use strict';
let NormalDataAutoRender = require('./NormalDataAutoRender');
let NormalDataStyleRender = require('./NormalDataStyleRender');
let MasterDetailAutoRender = require('./MasterDetailAutoRender');
let MasterDetailStyleRender = require('./MasterDetailStyleRender');

/**
 *PDF渲染
 *
 * @class PDFRender
 */
class PDFRender {
    /**
     *获取PDF文档
     *
     * @param {*} res
     * @param {*} data
     * @param {*} style
     * @returns
     * @memberof PDFRender
     */
    render(res, data, style) {
        if (!data) return false;
        data = typeof data === 'string' ? JSON.parse(data) : data;
        style = typeof style === 'string' ? JSON.parse(style) : style;
        let render = {};
        if (data.masterDetailKeyFields) {
            if (style) {
                render = new MasterDetailStyleRender(data, style);
            } else {
                render = new MasterDetailAutoRender(data, style);
            }
        } else {
            if (style) {
                render = new NormalDataStyleRender(data, style);
            } else {
                render = new NormalDataAutoRender(data, style);
            }
        }
        render.render(res);
    }
}

exports = module.exports = PDFRender;